package com.redfootdev.horseskills;

import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

public class Strength {

	public int horseWasHitBySomething(HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider, int damage) {
		// first decide if there is going to be any damage.
		
		
		// look up the horse and player attributes.
		Skill strength = hdb.getStrength(horse);
		Skill horsemanship = pdb.getHorsemanship(rider);
		// calculate the XP gain for strength.
		int xpGainStrength = (int)(damage*20*(1+horsemanship.getLevel()/100));
		// apply XP to strength Skill
		if(strength.addXP(xpGainStrength)) {
			rider.sendMessage(ChatColor.AQUA + "Your Strength level is now " + strength.getLevel() + ".");
			this.upgradeAbilities((Horse)horse, rider, strength.getLevel());
		}
		hdb.setStrength(horse, strength);
		
		return xpGainStrength;
		
		
	}
	
	public boolean HorseCanCarryWeight (HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider, int weight) {
		Skill strength = hdb.getStrength(horse);
		
		//TODO: Both configurable options. Starting carry weight, and bump per level.
		
		int maxWeight = strength.getLevel()*10+32;
		return maxWeight >= weight;
	}
	
	public String toString(HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider) {

		Skill strength = hdb.getStrength(horse);


		int level = strength.getLevel();
		int xp = strength.getXP();
		
		
		String stats = ChatColor.AQUA + "Strength Level: " + level + "\nExperience: " + xp;
		return stats;
	}
	public int HorseWasRiddenForTime(HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider, int time) {
		
		Skill strength = hdb.getStrength(horse);
		// calculate the XP gain for strength.
		int xpGainStrength = (int)(time/3);
		// apply XP to strength Skill
		if(strength.addXP(xpGainStrength)) {
			rider.sendMessage(ChatColor.AQUA + "Your Strength level is now " + strength.getLevel() + ".");
		}
		hdb.setStrength(horse, strength);
		
		return xpGainStrength;
		
		
	}
	public void upgradeAbilities(Horse horse, Player rider, int level) {
		horse.setMaxHealth(horse.getMaxHealth()*(1+level/100));
		
		
	}
	
}
